<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var craftsmanDataGrid;
    $(function() {
        craftsmanDataGrid = $('#craftsmanDataGrid').datagrid({
        url : '${path}/craftsman/dataGrid',
        striped : true,
        rownumbers : true,
        pagination : true,
        singleSelect : true,
        idField : 'id',
        sortName : 'manBrand',
        sortOrder : 'asc',
        pageSize : 20,
        pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500],
        frozenColumns : [ [ {
            width : '130',
            title : '品牌Logo',
            field : 'manBrandLogo',
            formatter : function(value, row, index) {
               return '<img id="preview" src='+value+' style="width: 120px; height: 150px;"/>';
            }
        },  {
            width : '140',
            title : '品牌名称',
            field : 'manBrand',
            sortable : true
        },  {
            width : '80',
            title : '品牌标识',
            field : 'manKey',
            sortable : true
        },{
            width : '140',
            title : '公司名称',
            field : 'manCompany',
            sortable : true
        },{
            width : '120',
            title : '设计师姓名',
            field : 'manName',
            sortable : true
        }, {
            width : '140',
            title : '职务',
            field : 'manPosition',
            sortable : true
        }, {
            width : '60',
            title : '性别',
            field : 'manSex',
            sortable : true,
            formatter : function(value, row, index) {
                switch (value) {
                case 0:
                    return '女';
                case 1:
                    return '男';
                }
            }
        },{
            field : 'action',
            title : '操作',
            width : 200,
            formatter : function(value, row, index) {
                var str = '';
                <shiro:hasPermission name="/craftsman/edit">
                    str += $.formatString('<a href="javascript:void(0)" class="craftsman-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="craftsmanEditFun(\'{0}\');" >编辑</a>', row.id);
                </shiro:hasPermission>
                <shiro:hasPermission name="/craftsman/delete">
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="craftsman-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="craftsmanDeleteFun(\'{0}\');" >删除</a>', row.id);
                </shiro:hasPermission>
                <shiro:hasPermission name="/craftsman/view">
	                str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
	                str += $.formatString('<a href="javascript:void(0)" class="craftsman-easyui-linkbutton-view" data-options="plain:true,iconCls:\'fi-eye icon-green\'" onclick="craftsmanViewFun(\'{0}\');" >查看</a>', row.id);
	            </shiro:hasPermission>
                return str;
            }
        } ] ],
        onLoadSuccess:function(data){
            $('.craftsman-easyui-linkbutton-edit').linkbutton({text:'编辑'});
            $('.craftsman-easyui-linkbutton-del').linkbutton({text:'删除'});
            $('.craftsman-easyui-linkbutton-view').linkbutton({text:'查看'});
        },
        toolbar : '#craftsmanToolbar'
    });
});

/**
 * 添加框
 * @param url
 */
function craftsmanAddFun() {
    parent.$.modalDialog({
        title : '添加',
        width : 700,
        height : 600,
        href : '${path}/craftsman/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = craftsmanDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#craftsmanAddForm');
                f.submit();
            }
        } ]
    });
}


/**
 * 编辑
 */
function craftsmanEditFun(id) {
    if (id == undefined) {
        var rows = craftsmanDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        craftsmanDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : 700,
        height : 600,
        overlay: { opacity: 0.5,
            background: "black",
            overflow: 'auto'
        },
        href :  '${path}/craftsman/editPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = craftsmanDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#craftsmanEditForm');
                f.submit();
            }
        } ]
    });
}

/**
 * 编辑
 */
function craftsmanViewFun(id) {
    if (id == undefined) {
        var rows = craftsmanDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        craftsmanDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '查看详情',
        width : 700,
        height : 600,
        overlay: { opacity: 0.5,
            background: "black",
            overflow: 'auto'
        },
        href :  '${path}/craftsman/viewPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = craftsmanDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#craftsmanViewForm');
                f.submit();
            }
        } ]
    });
}

function craftsmanViewProductFun(id){
    if (id == undefined) {
        var rows = craftsmanDataGrid.datagrid('getSelections');
        id = rows[0].id;
    } else {
        craftsmanDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
    }
    self.location='${path}/production/manager?id=' + id;
    
   /*
    parent.$.modalDialog({
        title : '查看详情',
        width : 700,
        height : 600,
        overlay: { opacity: 0.5,
            background: "black",
            overflow: 'auto'
        },
        href :  '${path}/craftsman/viewProductPage?id=' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_dataGrid = craftsmanDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#craftsmanViewForm');
                f.submit();
            }
        } ]
    });
    */
}
/**
 * 删除
 */
 function craftsmanDeleteFun(id) {
     if (id == undefined) {//点击右键菜单才会触发这个
         var rows = craftsmanDataGrid.datagrid('getSelections');
         id = rows[0].id;
     } else {//点击操作里面的删除图标会触发这个
         craftsmanDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
     }
     parent.$.messager.confirm('询问', '您是否要删除当前角色？', function(b) {
         if (b) {
             progressLoad();
             $.post('${path}/craftsman/delete', {
                 id : id
             }, function(result) {
                 if (result.success) {
                     parent.$.messager.alert('提示', result.msg, 'info');
                     craftsmanDataGrid.datagrid('reload');
                 }
                 progressClose();
             }, 'JSON');
         }
     });
}


/**
 * 清除
 */
function craftsmanCleanFun() {
    $('#craftsmanSearchForm input').val('');
    craftsmanDataGrid.datagrid('load', {});
}
/**
 * 搜索
 */
function craftsmanSearchFun() {
     craftsmanDataGrid.datagrid('load', $.serializeObject($('#craftsmanSearchForm')));
}
</script>

<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'north',border:false" style="height: 30px; overflow: hidden;background-color: #fff">
        <form id="craftsmanSearchForm">
            <table>
                <tr>
                    <th>品牌名称:</th>
                    <td><input name="manBrand" placeholder="品牌"/></td>
                    <th>公司名称:</th>
                    <td><input name="manCompany" placeholder="公司名称"/></td>
                    <th>设计师:</th>
                    <td><input name="manName" placeholder="设计师"/></td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="craftsmanSearchFun();">查询</a>
                        <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="craftsmanCleanFun();">清空</a>
                    </td>
                </tr>
            </table>
        </form>
     </div>
 
    <div data-options="region:'center',border:false">
        <table id="craftsmanDataGrid" data-options="fit:true,border:false"></table>
    </div>
    <!-- 
    <div data-options="region:'west',border:true,split:false,title:'组织机构'"  style="width:150px;overflow: hidden; ">
        <ul id="organizationTree" style="width:160px;margin: 10px 10px 10px 10px">
        	<li>吉祥</li>
        	<li>吉祥1</li>
        	<li>吉祥2</li>
        </ul>
    </div>
     -->
</div>
<div id="craftsmanToolbar" style="display: none;">
    <shiro:hasPermission name="/craftsman/add">
        <a onclick="craftsmanAddFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-page-add'">添加</a>
    </shiro:hasPermission>
</div>
